﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace SusyGame_Model
{
    public class Defender : Sprite
    {
        //Atributos
        protected int price;
        protected int damage;
        protected float radius;
        protected Enemy target;

        public Enemy Target
        {
            get { return target; }
            set { target = value; }
        }

        public float Radius
        {
            get { return radius; }
            set { radius = value; }
        }

        public int Damage
        {
            get { return damage; }
            set { damage = value; }
        }
        
        public int Price
        {
            get { return price; }
            set { price = value; }
        }

        public Defender(Texture2D texture, Vector2 position): base(texture, position)
        {
            this.radius = 1000;
        }

        public bool IsInRange(Vector2 position)
        {
            if (Vector2.Distance(base.Center, position) <= radius)
                return true;

            return false;
        }

        public void GetClosestEnemy(List<Enemy> enemies)
        {
            target = null;
            float smallestRange = radius;

            foreach (Enemy enemy in enemies)
            {
                if (Vector2.Distance(base.Center, enemy.Center) < smallestRange)
                {
                    smallestRange = Vector2.Distance(center, enemy.Center);
                    target = enemy;
                }
            }
        }

        protected void FaceTarget()
        {
            Vector2 direction = center - target.Center;
            direction.Normalize();

            rotation = (float)Math.Atan2(-direction.X, direction.Y);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (target != null)
                FaceTarget();
        }

        //private String name;
        //private int typeLand;
        //private String description;
        
        //private int shotSpeed; //Cada cuanto tiempo dispara
        //private int type;
        //private char icon;

        //private Weapon weapon;
        //private Pool pool;
        //private Ground ground;

        //Propiedades
        //public String Name
        //{
        //    get { return name; }
        //    set { name = value; }
        //}

        //public int TypeLand
        //{
        //    get { return typeLand; }
        //    set { typeLand = value; }
        //}        

        //public String Description
        //{
        //    get { return description; }
        //    set { description = value; }
        //}


       
        //public int ShotSpeed
        //{
        //    get { return shotSpeed; }
        //    set { shotSpeed = value; }
        //}

        //public int Type
        //{
        //    get { return type; }
        //    set { type = value; }
        //}        

        //public char Icon
        //{
        //    get { return icon; }
        //    set { icon = value; }
        //}
           
        //Constructores
        //public Defender()
        //{
        //}

        //public Defender(int type)
        //{
        //    if (type == 1)
        //    {
        //        //Le asignamos los valores de los atributos a los defensores
        //        this.Name = "Susy";
        //        this.Description = "Descripcion defensor tipo Susy";
        //        this.Price = 50;
        //        this.ShotSpeed = 1;
        //        this.weapon = new Weapon(1);               
        //        this.Icon = 'S';
        //        this.TypeLand = 1;
        //    }
        //    else
        //    {
        //        if (type == 2)
        //        {
        //            this.Name = "Lulu";
        //            this.Description = "Descripcion defensor tipo Lulu";
        //            this.Price = 100;
        //            this.ShotSpeed = 2;
        //            this.weapon = new Weapon(2);
        //            this.Icon = 'L';
        //            this.TypeLand = 2;
        //        }
        //        else
        //        {
        //            if (type == 3)
        //            {
        //                this.Name = "Charo";
        //                this.Description = "Descripcion defensor tipo Charo";
        //                this.Price = 150;
        //                this.ShotSpeed = 3;
        //                this.weapon = new Weapon(3);
        //                //this.Ground = .. ;
        //                //this.Pool = .. ;
        //                this.Icon = 'C';
        //                this.TypeLand = 1;
        //            }
        //            else
        //            {
        //                if (type == 4)
        //                {
        //                    this.Name = "Tere";
        //                    this.Description = "Descripcion defensor tipo Tere";
        //                    this.Price = 200;
        //                    this.ShotSpeed = 4;
        //                    this.weapon = new Weapon(4);
        //                    //this.Ground = .. ;
        //                    //this.Pool = .. ;
        //                    this.Icon = 'T';
        //                    this.TypeLand = 2;
        //                }
        //            }
        //        }
        //    }
        //    this.Type = type;
        //}
    }
}
